<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2025/5/4
  Time: 16:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.project.DB_Order" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
    <title>订单管理系统</title>
    <style>
        table {
            border-collapse: collapse;
            width: 100%;
        }
        table th, table td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }
        table tr:nth-child(even) {
            background-color: #f2f2f2;
        }
    </style>
</head>
<body>
<h2>订单管理系统</h2>

<!-- 查询表单 -->
<form action="index.jsp" method="get">
    <select name="conditionColumn">
        <option value="oid">订单ID</option>
        <option value="uid">用户ID</option>
        <option value="aid">航线ID</option>
    </select>
    <input type="text" name="conditionValue" placeholder="输入查询值">
    <input type="submit" value="查询">
</form>

<!-- 显示订单列表 -->
<table>
    <thead>
    <tr>
        <th>订单ID</th>
        <th>用户ID</th>
        <th>航线ID</th>
        <th>订单时间</th>
        <th>支付金额</th>
        <th>订单状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <%
        DB_Order dbOrder = new DB_Order();
        String conditionColumn = request.getParameter("conditionColumn");
        if (conditionColumn == null) {
            conditionColumn = "";
        }
        String conditionValue = request.getParameter("conditionValue");
        if (conditionValue == null) {
            conditionValue = "";
        }
        List<String> returnList = new ArrayList<>();
        dbOrder.find(conditionColumn, conditionValue, returnList);
        for (int i = 0; i < returnList.size(); i += 6) {
    %>
    <tr>
        <td><%= returnList.get(i) %></td>
        <td><%= returnList.get(i + 1) %></td>
        <td><%= returnList.get(i + 2) %></td>
        <td><%= returnList.get(i + 3) %></td>
        <td><%= returnList.get(i + 4) %></td>
        <td><%= returnList.get(i + 5) %></td>
        <td>
            <a href="editOrder.jsp?oid=<%= returnList.get(i) %>">编辑</a>
            <a href="deleteOrder.jsp?oid=<%= returnList.get(i) %>">删除</a>
        </td>
    </tr>
    <% } %>
    </tbody>
</table>

<!-- 添加订单表单 -->
<h2>添加订单</h2>
<form action="addOrder.jsp" method="post">
    <label for="uid">用户ID:</label>
    <input type="text" id="uid" name="uid" required><br>
    <label for="aid">航线ID:</label>
    <input type="text" id="aid" name="aid" required><br>
    <label for="payamount">支付金额:</label>
    <input type="text" id="payamount" name="payamount" required><br>
    <input type="submit" value="添加订单">
</form>
</body>
</html>